//
//  GXUserModel.m
//  GaoXunTravel
//
//  Created by 杜梅 on 16/5/31.
//  Copyright © 2016年 May. All rights reserved.
//

#import "GXUserModel.h"
#import "GXPublicStorage.h"

#define k_RCToken  @"kRCToken" //
#define k_ISLOGINED                             @"kISLOGINED"//
#define k_USER_ID                               @"kUSERID"//
#define k_USERNAME                              @"kUSERNAME"
#define k_UUID                                  @"UUID"
#define k_TOKEN                                 @"kTOKEN"
#define k_PASSWORD                              @"kPASSWORD"
#define k_SESSIONID                             @"SESSIONID"
#define k_HEADURL                               @"HEADURL"
#define k_FILEUSERICON                          @"FILEUSERICON"
#define k_UIDSTRING                             @"UIDSTRING"
#define k_BAKSTRING                             @"BAKSTRING"
#define k_LOGINTYPE                             @"LOGINTYPE"
#define k_ID                                    @"ID"
#define k_ROLENUM                               @"ROLENUM"
#define k_CUSTOMERGROUPID                                       @"KCUSTOMERGROUPID"
#define k_NICKNAME  @"KNICKNAME"
#define k_JOB  @"KJOB"
#define k_REMARK  @"KREMARK"
#define k_UNREADNOTICECOUNT  @"KUNREADNOTICECOUNT"
#define k_EMAIL  @"KEMAIL"
#define k_ADDRESS  @"KADDRESS"
#define k_CELLPHONE  @"KCELLPHONE"
#define k_SEX  @"KSEX"
#define k_REGISTRATION  @"KREGISTRATION"
#define k_TABBAR        @"KTABBAR"
@implementation GXUserModel
@synthesize RCToken                  =  _RCToken;
@synthesize password                 =  _password;
@synthesize token                    =  _token;
@synthesize nikName                  =  _nikName;
@synthesize userName                 =  _userName;
@synthesize sessionid                = _sessionid;
@synthesize user_id                  = _user_id;
@synthesize headUrl                  = _headUrl;
@synthesize fileUserIcon             = _fileUserIcon;
@synthesize job                      = _job;
@synthesize uidString                = _uidString;
@synthesize bakString                = _bakString;
@synthesize loginType                = _loginType;
@synthesize ID                       = _ID;
@synthesize role_num                 = _role_num;
@synthesize customerGroupId          = _customerGroupId;
@synthesize remark                   = _remark;
@synthesize unReadNoticeCount        = _unReadNoticeCount;
@synthesize email                    = _email;
@synthesize address                  = _address;
@synthesize cellphone                = _cellphone;
@synthesize sex                      = _sex;
@synthesize registration             = _registration;
@synthesize Tabbar                   = _Tabbar;
static GXUserModel *newInstance =nil;
static dispatch_once_t predicate;

+ (GXUserModel *)shareInstance
{
    dispatch_once(&predicate, ^{
        newInstance=[[GXUserModel alloc]init];
    });
    return newInstance;
}

+ (void)saveLoginUserInfo
{
    //存储登录的用户信息
    [[GXPublicStorage newInstance] archiverDataWithObject:[GXUserModel shareInstance]];
}

+(void)loadLoginUserInfo
{
    //读取登录用户信息
    GXUserModel *userModel = [[GXPublicStorage newInstance] unArchiverDataWithKey];
    [userModel toString];
    [GXUserModel shareInstance].isLogined = userModel.isLogined;
    [GXUserModel shareInstance].token = userModel.token;
    [GXUserModel shareInstance].userName = userModel.userName;
   // [GXUserModel shareInstance].UUIDString = [GXStringUtils genUIIDString];
    [GXUserModel shareInstance].password = userModel.password;
    [GXUserModel shareInstance].sessionid = userModel.sessionid;
    [GXUserModel shareInstance].user_id = userModel.user_id;
    [GXUserModel shareInstance].headUrl = userModel.headUrl;
    [GXUserModel shareInstance].uidString = userModel.uidString;
    [GXUserModel shareInstance].bakString = userModel.bakString;
    [GXUserModel shareInstance].loginType = userModel.loginType;
    [GXUserModel shareInstance].ID = userModel.ID;
    [GXUserModel shareInstance].role_num = userModel.role_num;
    [GXUserModel shareInstance].customerGroupId = userModel.customerGroupId;
    [GXUserModel shareInstance].RCToken = userModel.RCToken;
    [GXUserModel shareInstance].nikName = userModel.nikName;
    [GXUserModel shareInstance].job = userModel.job;
    [GXUserModel shareInstance].remark = userModel.remark;
    [GXUserModel shareInstance].unReadNoticeCount = userModel.unReadNoticeCount;
    [GXUserModel shareInstance].email = userModel.email;
    [GXUserModel shareInstance].address = userModel.address;
    [GXUserModel shareInstance].cellphone = userModel.cellphone;
    [GXUserModel shareInstance].sex = userModel.sex;
    [GXUserModel shareInstance].registration = userModel.registration;
    [GXUserModel shareInstance].Tabbar = userModel.Tabbar;
    NSLog(@"读取用户登录信息");
}


- (id)initWithCoder:(NSCoder *)aDecoder
{
    self=[super init];
    if (self) {
        //解档
        self.isLogined = [aDecoder decodeBoolForKey:k_ISLOGINED];
        self.token = [aDecoder decodeObjectForKey:k_TOKEN];
        self.userName = [aDecoder decodeObjectForKey:k_USERNAME];
        self.UUIDString = [aDecoder decodeObjectForKey:k_UUID];
        self.password = [aDecoder decodeObjectForKey:k_PASSWORD];
        self.sessionid = [aDecoder decodeObjectForKey:k_SESSIONID];
        self.user_id= [aDecoder decodeObjectForKey:k_USER_ID];
        self.headUrl = [aDecoder decodeObjectForKey:k_HEADURL];
        self.uidString = [aDecoder decodeObjectForKey:k_UIDSTRING];
        self.bakString = [aDecoder decodeObjectForKey:k_BAKSTRING];
        self.loginType = [aDecoder decodeObjectForKey:k_LOGINTYPE];
        self.ID = [aDecoder decodeObjectForKey:k_ID];
        self.role_num = [aDecoder decodeObjectForKey:k_ROLENUM];
        self.customerGroupId = [aDecoder decodeObjectForKey:k_CUSTOMERGROUPID];
        self.RCToken = [aDecoder decodeObjectForKey:k_RCToken];
        self.nikName = [aDecoder decodeObjectForKey:k_NICKNAME];
        self.job = [aDecoder decodeObjectForKey:k_JOB];
        self.remark = [aDecoder decodeObjectForKey:k_REMARK];
        self.unReadNoticeCount = [aDecoder decodeObjectForKey:k_UNREADNOTICECOUNT];
        self.email = [aDecoder decodeObjectForKey:k_EMAIL];
        self.address = [aDecoder decodeObjectForKey:k_ADDRESS];
        self.cellphone = [aDecoder decodeObjectForKey:k_CELLPHONE];
        self.sex = [aDecoder decodeObjectForKey:k_SEX];
        self.registration = [aDecoder decodeObjectForKey:k_REGISTRATION];
        self.Tabbar = [aDecoder decodeObjectForKey:k_TABBAR];
    }
    return self;
}


- (void)encodeWithCoder:(NSCoder *)aCoder
{
    //归档
    [aCoder encodeBool:self.isLogined forKey:k_ISLOGINED];
    [aCoder encodeObject:self.token forKey:k_TOKEN];
    [aCoder encodeObject:self.userName forKey:k_USERNAME];
    [aCoder encodeObject:self.UUIDString forKey:k_UUID];
    [aCoder encodeObject:self.password forKey:k_PASSWORD];
    [aCoder encodeObject:self.sessionid forKey:k_SESSIONID];
    [aCoder encodeObject:self.user_id forKey:k_USER_ID];
    [aCoder encodeObject:self.headUrl forKey:k_HEADURL];
    [aCoder encodeObject:self.uidString forKey:k_UIDSTRING];
    [aCoder encodeObject:self.bakString forKey:k_BAKSTRING];
    [aCoder encodeObject:self.loginType forKey:k_LOGINTYPE];
    [aCoder encodeObject:self.ID forKey:k_ID];
    [aCoder encodeObject:self.role_num forKey:k_ROLENUM];
    [aCoder encodeObject:self.customerGroupId forKey:k_CUSTOMERGROUPID];
    [aCoder encodeObject:self.RCToken forKey:k_RCToken];
    [aCoder encodeObject:self.nikName forKey:k_NICKNAME];
    [aCoder encodeObject:self.job forKey:k_JOB];
    [aCoder encodeObject:self.remark forKey:k_REMARK];
    [aCoder encodeObject:self.unReadNoticeCount forKey:k_UNREADNOTICECOUNT];
    [aCoder encodeObject:self.email forKey:k_EMAIL];
    [aCoder encodeObject:self.address forKey:k_ADDRESS];
    [aCoder encodeObject:self.cellphone forKey:k_CELLPHONE];
    [aCoder encodeObject:self.sex forKey:k_SEX];
    [aCoder encodeObject:self.registration forKey:k_REGISTRATION];
    [aCoder encodeObject:self.Tabbar forKey:k_TABBAR];
}
#pragma mark ---- 角色
-(void)setRole_num:(NSString *)role_num {
    if ([role_num isKindOfClass:[NSNull class]]) {
        role_num = @"";
    }
    if (_role_num != role_num) {
        _role_num = role_num;
    }
}

-(NSString *)role_num {
    if ([_role_num isKindOfClass:[NSNull class]]) {
        _role_num = @"";
    }
    return _role_num;
}


-(void)setID:(NSString *)ID {
    if ([ID isKindOfClass:[NSNull class]]) {
        ID = @"";
    }
    if (_ID != ID) {
        _ID = ID;
    }
}

-(NSString *)ID {
    if ([_ID isKindOfClass:[NSNull class]]) {
        _ID = @"";
    }
    return _ID;
}

-(void)setLoginType:(NSString *)loginType {
    if ([loginType isKindOfClass:[NSNull class]]) {
        loginType = @"";
    }
    if (_loginType != loginType) {
        _loginType = loginType;
    }
}

-(NSString *)loginType {
    if ([_loginType isKindOfClass:[NSNull class]]) {
        _loginType = @"";
    }
    return _loginType;
}

-(void)setBakString:(NSString *)bakString {
    if ([bakString isKindOfClass:[NSNull class]]) {
        bakString = @"";
    }
    if (_bakString != bakString) {
        _bakString = bakString;
    }
}

-(NSString *)bakString {
    if ([_bakString isKindOfClass:[NSNull class]]) {
        _bakString = @"";
    }
    return _bakString;
}

-(void)setUidString:(NSString *)uidString {
    if ([uidString isKindOfClass:[NSNull class]]) {
        uidString = @"";
    }
    if (_uidString != uidString) {
        _uidString = uidString;
    }
}

-(NSString *)uidString {
    if ([_uidString isKindOfClass:[NSNull class]]) {
        _uidString = @"";
    }
    return _uidString;
}

#pragma mark ---- 用户名
- (void)setUserName:(NSString *)userName
{
    if ([userName isKindOfClass:[NSNull class]]) {
       userName = @"";
    }
    if (_userName != userName) {
        _userName = userName;
    }

}

- (NSString *)userName
{
    if ([_userName isKindOfClass:[NSNull class]]) {
        _userName = @"";
    }
    return _userName;
}

#pragma mark ---- 密码
- (void)setPassword:(NSString *)password
{
    if ([password isKindOfClass:[NSNull class]]) {
        password = @"";
    }
    if (_password != password) {
        _password = password;
    }
}

- (NSString *)password
{
    if ([_password isKindOfClass:[NSNull class]]) {
        _password = @"";
    }
    return _password;
}

#pragma mark ---- 职业
- (void)setJob:(NSString *)job
{
    if ([job isKindOfClass:[NSNull class]]) {
        job = @"";
    }
    if (_job != job) {
        _job = job;
    }
}

- (NSString *)job
{
    if ([_job isKindOfClass:[NSNull class]]) {
        _job = @"";
    }
    return _job;
}

- (void)setCustomerGroupId:(NSString *)customerGroupId {
    if ([customerGroupId isKindOfClass:[NSNull class]]) {
        customerGroupId = @"";
    }
    if (_customerGroupId != customerGroupId) {
        _customerGroupId = customerGroupId;
    }

}

- (NSString *)customerGroupId {
    if ([_customerGroupId isKindOfClass:[NSNull class]]) {
        _customerGroupId = @"";
    }
    return _customerGroupId;
}

#pragma mark ---- 融云token
- (void)setRCToken:(NSString *)RCToken {
    if ([RCToken isKindOfClass:[NSNull class]]) {
        RCToken = @"";
    }
    if (_RCToken != RCToken) {
        _RCToken = RCToken;
    }
}
- (NSString *)RCToken {
    if ([_RCToken isKindOfClass:[NSNull class]]) {
        _RCToken = @"";
    }
    return _RCToken;
}

#pragma mark ---- 昵称
- (void)setNikName:(NSString *)nikName {
    if ([nikName isKindOfClass:[NSNull class]]) {
        nikName = @"";
    }
    if (_nikName != nikName) {
        _nikName = nikName;
    }
}

- (NSString *)nikName {
    if ([_nikName isKindOfClass:[NSNull class]]) {
        _nikName = @"";
    }
    return _nikName;
}

#pragma mark ---- 个人说明
- (void)setRemark:(NSString *)remark {
    if ([remark isKindOfClass:[NSNull class]]) {
        remark = @"";
    }
    if (_remark != remark) {
        _remark = remark;
    }
}

- (NSString *)remark {
    if ([_remark isKindOfClass:[NSNull class]]) {
        _remark = @"";
    }
    return _remark;
}

#pragma mark ---- 未读通知数
- (void)setUnReadNoticeCount:(NSString *)unReadNoticeCount {
    if ([unReadNoticeCount isKindOfClass:[NSNull class]]) {
        unReadNoticeCount = @"";
    }
    if (_unReadNoticeCount != unReadNoticeCount) {
        _unReadNoticeCount = unReadNoticeCount;
    }
}

- (NSString *)unReadNoticeCount {
    if ([_unReadNoticeCount isKindOfClass:[NSNull class]]) {
        _unReadNoticeCount = @"";
    }
    return _unReadNoticeCount;
}

#pragma mark ---- 邮箱
- (void)setEmail:(NSString *)email {
    if ([email isKindOfClass:[NSNull class]]) {
        email = @"";
    }
    if (_email != email) {
        _email = email;
    }
}

- (NSString *)email {
    if ([_email isKindOfClass:[NSNull class]]) {
        _email = @"";
    }
    return _email;
}
#pragma mark ---- 地址
- (void)setAddress:(NSString *)address {
    if ([address isKindOfClass:[NSNull class]]) {
        address = @"";
    }
    if (_address != address) {
        _address = address;
    }
}

- (NSString *)address {
    if ([_address isKindOfClass:[NSNull class]]) {
        _address = @"";
    }
    return _address;
}
#pragma mark ---- 手机号
- (void)setCellphone:(NSString *)cellphone {
    if ([cellphone isKindOfClass:[NSNull class]]) {
        cellphone = @"";
    }
    if (_cellphone != cellphone) {
        _cellphone = cellphone;
    }
}

- (NSString *)cellphone {
    if ([_cellphone isKindOfClass:[NSNull class]]) {
        _cellphone = @"";
    }
    return _cellphone;
}

#pragma mark ---- 性别
- (void)setSex:(NSString *)sex {
    if ([sex isKindOfClass:[NSNull class]]) {
        sex = @"";
    }
    if (_sex != sex) {
        _sex = sex;
    }
}

- (NSString *)sex {
    if ([_sex isKindOfClass:[NSNull class]]) {
        _sex = @"";
    }
    return _sex;
}
#pragma mark ---- 邀请码
- (void)setRegistration:(NSString *)registration {
    if ([registration isKindOfClass:[NSNull class]]) {
        registration = @"";
    }
    if (_registration != registration) {
        _registration = registration;
    }
}

- (NSString *)registration {
    if ([_registration isKindOfClass:[NSNull class]]) {
        _registration = @"";
    }
    return _registration;
}

- (void)setTabbar:(LYTabBarViewController *)Tabbar {
    if ([Tabbar isKindOfClass:[NSNull class]]) {
        Tabbar = nil;
    }
    if (_Tabbar != Tabbar) {
        _Tabbar = Tabbar;
    }
}

- (LYTabBarViewController *)Tabbar {
    if ([_Tabbar isKindOfClass:[NSNull class]]) {
        _Tabbar = nil;
    }
    return _Tabbar;
}
- (void)toString
{
    NSLog(@"===MMDUserModel toString userName:%@, password:%@,baking:%@ user_id:%@,id:%@ ,typestring:%@,uidstring:%@", self.userName,self.password,self.bakString,self.user_id,self.ID,self.loginType,self.uidString);
}

@end
